﻿using System;
using System.Linq.Expressions;
using MoroMoro.Samples.ToDoList.Base.Domain.Specifications;
using MoroMoro.Samples.ToDoList.Base.Domain.Expanders;

namespace MoroMoro.Samples.ToDoList.Domain.ToDos
{
    /// <summary>
    /// <see cref="ToDo"/>の<see cref="ToDo.State">状態</see>が特定の状態と一致するかどうかを判断します。
    /// </summary>
    [Serializable]
    public sealed class ToDoStateSpecification : Specification<ToDo>
    {
        /// <summary>
        /// <see cref="ToDoStateSpecification"/> クラスの新しいインスタンスを初期化します。
        /// </summary>
        /// <param name="state"><see cref="ToDo.State">状態</see>。</param>
        public ToDoStateSpecification(ToDoState state)
        {
            _state = state;
        }


        /// <summary>
        /// <see cref="ToDo.State">状態</see>。
        /// </summary>
        private readonly ToDoState _state;


        /// <inheritdoc/>
        protected override Expression<Func<ToDo, bool>> CreateExpression()
        {
            return entity => (entity.State == _state);
        }


        /// <inheritdoc/>
        protected override Expander<ToDo> GetExpander()
        {
            return new Expander<ToDo>(new ToDoStateViewpoint());
        }
    }
}
